Add DivertorNumberModels enum and refactor i_single_null usage across…#4218
Conversation
… models Co-authored-by: Copilot <copilot@github.com>
4db632a to
0cc91ae
Compare
There was a problem hiding this comment.
Pull request overview
This PR introduces a DivertorNumberModels IntEnum intended to replace the raw i_single_null magic numbers (0/1) and refactors several model call sites to compare against the enum values for improved readability/consistency.
Changes:
- Add
DivertorNumberModelsenum (intended mapping:DOUBLE_NULL=0,SINGLE_NULL=1). - Refactor
i_single_nullcomparisons in TF coil shaping, plasma geometry, divertor heat-load sizing, and build/init validation logic. - Start casting
physics_variables.i_single_nullto the enum in parts ofprocess/models/build.pyandprocess/core/init.py.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| process/models/build.py | Adds DivertorNumberModels and uses it in vertical/radial build logic. |
| process/models/tfcoil/base.py | Uses the enum in TF coil inner shape logic and adds an import for it. |
| process/models/geometry/plasma.py | Uses the enum in plasma boundary generation for single vs double null. |
| process/models/divertor.py | Uses the enum to choose single vs double null divertor area calculation. |
| process/core/init.py | Casts i_single_null to the enum for initialization-time configuration checks. |
Comments suppressed due to low confidence (2)
process/models/build.py:183
- i_single_null is only assigned inside the
if output:block, but it is later used unconditionally (e.g., the divertor coil vertical location logic). Whenoutputis False, this will raise UnboundLocalError. Define/cast i_single_null before theif output:so it is always available.
i_single_null = DivertorNumberModels(physics_variables.i_single_null)
if i_single_null == DivertorNumberModels.DOUBLE_NULL:
process/models/divertor.py:189
- If i_single_null is not SINGLE_NULL or DOUBLE_NULL, neither branch assigns
areadv, but it is used immediately afterwards (pflux_div_heat_load_mw calculation), which will raise UnboundLocalError. Add an explicit else branch that raises ProcessValueError/ProcessValidationError (or otherwise handles unexpected values) so invalid inputs fail with a clear error.
elif i_single_null == DivertorNumberModels.DOUBLE_NULL:
areadv = 2.0 * (a1 + a2 + a3)
if self.data.divertor.i_div_heat_load == 1:
self.data.divertor.pflux_div_heat_load_mw = p_plasma_separatrix_mw / areadv
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| from process.models.build import DivertorNumberModels | ||
| from process.models.superconductors import SuperconductorModel |
| class DivertorNumberModels(IntEnum): | ||
| """Enum for divertor number models. `i_single_null` is the index for this enum.""" | ||
|
|
||
| DOUBLE_NULL = 0 | ||
| SINGLE_NULL = 1 |
timothy-nunn
left a comment
There was a problem hiding this comment.
Looks like there is an import cycle. You can probably split the enum out into another file with a couple of other enums. Maybe we should talk tomorrow about exactly which enums should go into this file or it could become a dumping ground
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #4218 +/- ##
==========================================
- Coverage 50.23% 50.14% -0.10%
==========================================
Files 151 151
Lines 29365 29355 -10
==========================================
- Hits 14752 14719 -33
- Misses 14613 14636 +23 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
… models
Description
Checklist
I confirm that I have completed the following checks: